<?php
namespace App\Http\Controllers\Api;

use App\Models\MMemberVerify;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

/**
 * 手机号码
 *
 */
class PhoneNumberController extends ApiController{
    /**
     * 手机号归属地
     *
     */
    public function phone_ownership(Request $request){
        $type = $request->type??1; // 1移动  2联通  3电信

        switch ( $type ) {
            case 1:
                $return_data = config("move.ownership");
                unset($return_data['X']);
                break;
            case 2:
                $return_data = config("move.ownership");
                break;
            case 3:
                $return_data = config("move.ownership");
                break;
            default:
                $return_data = config("move.ownership");
        }

        return $this->ReturnMessage(200, 'success', $return_data);
    }

    /**
     * 手机号号池
     *
     */
    public function phone_number(Request $request){
        $type = $request->type??1; // 1移动  2联通  3电信
        $part = $request->part; // 手机号归属地
        $size = $request->size??10;
        $returnArray = [];
        if ( !$part ) {
            return $this->ReturnMessage(-1, '参数错误');
        }
        if ($type == 1) {
            // 移动号池
            $code = 'UIP_CARD_QRYPOOL_RT';
            $data = $this->getPhoneNumber($code, $part);
            Log::info('移动号池', $data);
        } elseif($type == 2) {
            // 联通号池
            $data['code'] = 201;
        } else {
            // 电信号池
            $data['code'] = 201;
        }
        $returnData = [];
        if ( $data['code'] == 200 ) {
            $numberArray = $data['data']['cardpool'];

            if(!empty($numberArray)){
                // 循环遍历出所有的手机号码
                foreach ($numberArray as $key=> $value) {
                    $returnArray[$key] = [
                        'owner_place' => $value['CARDREGION'],
                        'number' => $value['CARDSVCNUM'],
                    ];
                }
            }

            $key = array_rand($returnArray, $size);
            for ($i=0; $i < $size; $i++) {
                $returnData[] = $returnArray[$key[$i]];
            }
        }

        return $this->ReturnMessage(200, '查询成功', $returnData);
    }
}
